package com.qf.business.course.core.controller;

import com.qf.business.course.core.service.CourseInfoService;
import com.qf.commons.data.base.BaseUser;
import com.qf.commons.data.result.R;
import com.qf.commons.web.aspect.annotation.GetUser;
import com.qf.commons.web.utils.UserUtils;
import com.qf.data.course.entity.CourseInfo;
import com.qf.data.course.vo.input.CourseInfoInput;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/course/info")
@Slf4j
public class CourseInfoController {

    @Autowired
    private CourseInfoService courseInfoService;

    /**
     * 新增课程的基本信息
     * @return
     */
    @RequestMapping("/insert")
    public R insert(CourseInfoInput courseInfoInput){
        log.debug("[course info insert] 新增课程信息 - {}", courseInfoInput);
        courseInfoService.save(courseInfoInput);
        return R.create("succ");
    }

    /**
     * 根据教师id查询该教师名下的相关课程
     * @return
     */
    @RequestMapping("/listByTid")
    @GetUser
    public R listByTid(){
        BaseUser user = UserUtils.getUser();
        List<CourseInfo> courseInfos = courseInfoService.queryByTid(user.getId());
        return R.create(courseInfos);
    }

    /**
     * 根据1级分类的id 查询该方法下所有的课程列表
     * @return
     */
    @RequestMapping("/queryByOneType")
    public R queryByOneType(Integer tid){
        return R.create(courseInfoService.queryByOneType(tid));
    }
}